<?php
namespace App\Services;
use App\Models\MallOrder;


class ZeroJoinCheckService {

    public static function handle($user) {
        if (!$user->is_vip) {
            if ($user->has_buy_zero_product) {
                return ['status' => -1, 'msg' => '请开通VIP套餐才允许参与零元购'];
            }
        } else {
            $month = date('Ym');
            $exist_wait_pay = MallOrder::where('user_id', $user->id)->where('month', $month)->where('status', MallOrder::STATUS_WAIT_PAY)->exists();
            if ($exist_wait_pay)
                return ['status' => -1, 'msg' => '订单列表已经存在一个零元商品待支付'];

            $exist_paid = MallOrder::where('user_id', $user->id)->where('month', $month)->whereNotNull('paid_at')->exists();
            if ($exist_paid) {
                return ['status' => -1, 'msg' => '一个月只允许参与一次'];
            }
        }
        return ['status' => 1];
    }

}
